using Rougamo;
using Rougamo.Context;
using System.Diagnostics;

namespace JGSY.Rougamo.AOP
{
    public class PerformanceAttribute : MoAttribute
    {
        [ThreadStatic]
        private static Stopwatch? _stopwatch;

        public override void OnEntry(MethodContext context)
        {
            _stopwatch = Stopwatch.StartNew();
            Console.WriteLine($"[性能] 开始监控方法: {context.Method.DeclaringType?.FullName}.{context.Method.Name}");
        }

        public override void OnExit(MethodContext context)
        {
            _stopwatch?.Stop();
            Console.WriteLine($"[性能] 方法 {context.Method.DeclaringType?.FullName}.{context.Method.Name} 执行耗时: {_stopwatch?.ElapsedMilliseconds}ms");
            _stopwatch = null;
        }
    }
}    